package com.ymatou.counter.api.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.counter.api.parameter.GetNaturalBean;
import com.ymatou.counter.api.service.GetNaturalCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.CounterCallService;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 获取单个计数器 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetNatural {
	private static GetNaturalBean getGetNaturalBean;
	private static GetNaturalCall getGetNaturalCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取单个计数器");
	}

	@Before
	public void caseUp() {
		getGetNaturalBean = new GetNaturalBean();
		getGetNaturalCall = new GetNaturalCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getGetNaturalCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNatural_001() {
		Logger.start(true,"获取单个计数器成功");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setAppId("Test");
			getGetNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0);
			getGetNaturalBean.setTime(DataTime);
			getGetNaturalBean.setTargetId(TargetId);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, getGetNaturalCall.getMsg(), "验证Msg");
			Logger.verifyEquals(value, getGetNaturalCall.getData(), "验证计数器值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNatural_002() {
		Logger.start(false,"不输入AppId,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0);
			getGetNaturalBean.setTime(DataTime);
			getGetNaturalBean.setTargetId(TargetId);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOAPPID_MSG, getGetNaturalCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNatural_003() {
		Logger.start(false,"不输入TargetId,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setAppId("Test");
			getGetNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0);
			getGetNaturalBean.setTime(DataTime);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTARGETID_MSG, getGetNaturalCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNatural_004() {
		Logger.start(false,"不输入counter,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setAppId("Test");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0);
			getGetNaturalBean.setTime(DataTime);
			getGetNaturalBean.setTargetId(TargetId);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOCOUNTER_MSG, getGetNaturalCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNatural_005() {
		Logger.start(false,"不输入时间，失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setAppId("Test");
			getGetNaturalBean.setCounter("nc1");
			getGetNaturalBean.setTargetId(TargetId);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getGetNaturalCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNatural_006() {
		Logger.start(false, "输入错误的AppId,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setAppId("ErrorTest");
			getGetNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0);
			getGetNaturalBean.setTime(DataTime);
			getGetNaturalBean.setTargetId(TargetId);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.ERROR500, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getGetNaturalCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNatural_007() {
		Logger.start(false,"输入错误的counter,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setAppId("Test");
			getGetNaturalBean.setCounter("errorc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0);
			getGetNaturalBean.setTime(DataTime);
			getGetNaturalBean.setTargetId(TargetId);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.ERROR500, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getGetNaturalCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNatural_008() {
		Logger.start(false,"错误的TargetId,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setAppId("Test");
			getGetNaturalBean.setCounter("nc1");
			String DataTime = YMTDateUtil.getBeforeOrNextDay(0);
			getGetNaturalBean.setTime(DataTime);
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			getGetNaturalBean.setTargetId(TargetId2);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, getGetNaturalCall.getMsg(), "验证Msg");
			Logger.verifyEquals(0, getGetNaturalCall.getData(), "验证计数器值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNatural_009() {
		Logger.start(false,"错误的时间");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 11;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getGetNaturalBean.setAppId("Test");
			getGetNaturalBean.setCounter("nc1");
			String DataTime = "aabbcc";
			getGetNaturalBean.setTime(DataTime);
			getGetNaturalBean.setTargetId(TargetId);
			getGetNaturalCall.setData(getGetNaturalBean);
			getGetNaturalCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getGetNaturalCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getGetNaturalCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}